//
//  OneTab.m
//  One
//
//  Created by youyoumacmini3 on 17/3/10.
//  Copyright © 2017年 youyoumacmini3. All rights reserved.
//

#import "OneTab.h"

@interface OneTab ()

@end

@implementation OneTab

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     /***  改变tabBar背景颜色的方法  ***/
    self.tabBar.tintColor = [UIColor orangeColor];
    [[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
        [UITabBar appearance].translucent = NO;
    
    // 方法2.
    //    UIView *view = [[UIView alloc]init];
    //    view.backgroundColor = [UIColor redColor];
    //    view.frame = self.tabBar.bounds;
    //    [[UITabBar appearance] insertSubview:view atIndex:0];
    
    // 方法3.
    //    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabBarBackgroundImage"]];
    //    [UITabBar appearance].translucent = NO;
    
    /***   选中item背景色   ***/
    CGSize indicatorImageSize = CGSizeMake(self.tabBar.bounds.size.width / self.tabBar.items.count, self.tabBar.bounds.size.height);
    
    //可以通过tabBar的selectionIndicatorImage属性来实现改变点击某个item后的背景色。
    self.tabBar.selectionIndicatorImage = [self drawTabBarItemBackgroundImageWithSize:indicatorImageSize];
    
}

- (UIImage *)drawTabBarItemBackgroundImageWithSize:(CGSize)size
{
    // 准备绘图环境
    UIGraphicsBeginImageContext(size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGContextSetRGBFillColor(ctx, 150.0 / 255, 80.0 / 255, 151.0 / 255, 1);
    CGContextFillRect(ctx, CGRectMake(0, 0, size.width, size.height));
    
    // 获取该绘图中的图片
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    
    //结束绘图
    UIGraphicsEndImageContext();
    
    /*
     // 获取当前应用路径中Documents目录下指定文件名对应的文件路径
     NSString *path = [[NSHomeDirectory() stringByAppendingString:@"/Documents"] stringByAppendingString:@"/tabBarBackgroundImage.png"];
     NSLog(@"path:%@", path);
     // 保存PNG图片
     [UIImagePNGRepresentation(img) writeToFile:path atomically:YES];
     */
    return img;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
